//
//  AHUCheckViewController.m
//  Qihuo
//
//  Created by Vencoo on 14-1-9.
//  Copyright (c) 2014年 Vencoo. All rights reserved.
//

#import "AHUCheckViewController.h"
#import "AHUCell.h"
@interface AHUCheckViewController ()
{
    NSArray *floorNames;
    NSMutableArray *checkNames;
}
@end

@implementation AHUCheckViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    self.checkURL = resultOfAHU;
    self.floorCheckDatas = [NSMutableArray array];
    [super viewDidLoad];
    self.title = @"AHU机房巡检记录" ;
    floorNames = @[@"设备编号",@"日期",@"巡检",@"巡检内容",@"保养",@"保养内容",@"签名"];
    checkNames = [NSMutableArray array];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return floorNames.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    AHUCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
    {
        cell = [[AHUCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
    }
    cell.floorNameLb.text = [floorNames objectAtIndex:indexPath.row];
    if (checkNames.count > 0)
    {
        cell.locationLb.text = [checkNames objectAtIndex:indexPath.row];
    }
    return cell;
}
#pragma mark - request
- (void)requestDone:(ASIFormDataRequest *)request
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    NSString *response = [request responseString];
    NSDictionary *queryDic = [response JSONValue];
    NSDictionary *queryDataArr = [queryDic objectForKey:@"data"];
    self.floorCheckDatas = [queryDataArr objectForKey:@"checkData"];
    [checkNames addObject:[[self.floorCheckDatas firstObject]
        valueForKey:@"device"]];
    [checkNames addObject:[[self.floorCheckDatas firstObject]
        valueForKey:@"date"]];
    [checkNames addObject:[[self.floorCheckDatas firstObject] valueForKey:@"inspection"]];
    [checkNames addObject:[[self.floorCheckDatas firstObject] valueForKey:@"inContent"]];
    [checkNames addObject:[[self.floorCheckDatas firstObject] valueForKey:@"maintenance"]];
    [checkNames addObject:[[self.floorCheckDatas firstObject] valueForKey:@"maContent"]];
    [checkNames addObject:[[self.floorCheckDatas firstObject] valueForKey:@"userName"]];
    
    NSLog(@"%@",checkNames);
    [self.mainTable reloadData];
}
- (void)requestFail
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    UIAlertView *failAlert = [[UIAlertView alloc]initWithTitle:@"警告" message:@"请求数据失败！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [failAlert show];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
